<!--<form class="layui-form" action="{:url('status', ['val'=>$val])}"  method="post" id="editForm">-->
<table id="dataTable"></table>
<div class="pop-bottom-bar">
        <a id="shenhe1" onclick="examine('#shenhe')" class="layui-btn layui-btn-normal">审核</a>
<button  type="submit" data-href="{:url('audit')}?mid={$order_material_id}" class="layui-btn layui-btn-normal j-page-btns closeLayer" id="shenhe" lay-submit="formSubmit" style="display: none"  lay-filter="formSubmit" >确定</button>
        <button  type="submit" data-href="{:url('status', ['val'=>$val])}" class="layui-btn layui-btn-normal j-page-btns closeLayer" id="formSubmit" lay-submit=""  lay-filter="formSubmit" refresh="true">确定</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
</div>
<!--</form>  pop: true, refresh: false,-->
{include file="system@block/layui" /}

<script type="text/html" id="createTimeTpl">
    <div>{{layui.util.toDateString(d.create_time * 1000) }}</div>
</script>
<script type="text/html" id="idTpl">
    <input readonly="readonly" style="border: none;display: none" type="text" name="id" value="{{d.id}}">
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
    {{# if("{$a}" == 'add'){ }}
        {{# if(d.type == 'accessories'){ }}
                <a href="{:url('mp/stock/add')}?material_sku={{ d.material_sku }}&client_ordernum={{ d.client_ordernum }}&material_return_id={{ d.id }}" title="辅料入库" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe" hisi-data="{width: '500px', height: '500px'}" callback="updateMaterialReturnStatus">入库</a>
            {{# }else{ }}
                <a href="{:url('mp/materialStock/add')}?material_sku={{ d.material_sku }}&client_ordernum={{ d.client_ordernum }}&material_return_id={{ d.id }}" title="余料入库" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe" hisi-data="{width: '500px', height: '500px',endRefresh:'true'}" callback="updateMaterialReturnStatus">入库</a>
        {{# } }}
    {{# } }}
</script>
<script type="text/javascript">
    layui.use(['table', 'tool','layer'], function() {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        table.render({
            elem: '#dataTable'
            ,url: "{:url('', ['order_material_id'=>$order_material_id,'status'=>$status,'a'=>$a])}" //数据接口
//            ,page: true //开启分页
//            ,skin: 'row'
//            ,even: true
//            ,limit: 20
//            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: false
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                 {type:'checkbox'}
                //,{field: 'id', title: '编号',templet: '#idTpl'}
                ,{field: 'supplier', title: '供应商'}
                ,{field: 'cloth_num', title: '布号'}
                ,{field: 'reason', title: '退换原因'}
                ,{field: 'rt_type', title: '退布类型'}
                ,{field: 'return_length', title: '退布米数'}
                ,{field: 'create_time', title: '退料时间',templet: '#createTimeTpl', width:160}
                ,{field: '', title: '操作', templet: '#buttonTpl'}
            ]]
            ,done: function(res, curr, count){
                var a="{$a}";
                if(a=="check"){
                    $(".layui-table-col-special").remove();
                }else if(a=="audit"){
                    $("#formSubmit").remove();
                }else{
                    $("#shenhe1").remove();
                }
                if(res.status==4){
                    $('.pop-bottom-bar').remove();
                }else if(res.status==5){
                    $('.pop-bottom-bar').remove();
                }
			}
        });
        window.examine = function(tag) {
            var layerFeed = layer.prompt({title: '审核：请输入退货米数', formType: 0,success:function(){
                // 键盘事件，判断回车
                $("input.layui-layer-input").on('keydown',function(e){
                });
            }}, 
            function(number){
                
                $(tag).attr("data-href");
                $(tag).attr("data-href",$(tag).attr("data-href")+"&billing_caigou_count_feed="+number);
                $(tag).click();
                //feedEvent(number, mid, obj);
            });
		}
        // 入库后回调
        window.updateMaterialReturnStatus = function(id) {
            if (id > 0) {
                //table.reload('dataTable');
                //parent.layui.table.reload('dataTable');
                window.parent.location.reload();
                parent.layer.closeAll();
                
//                var ori = parseInt($('.stat-num-{$status}').html());
//                $('.stat-num-{$status}').html(ori-1);
//
//                // 审核中标签统计数加1
//                var oriAudit = parseInt($('.stat-num-2').html());
//                $('.stat-num-{$status}').html(oriAudit+1);
            }
        }
        
    });
</script>